/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.unittests.struts.service.beans;

import opiam.admin.faare.PropertiesManager;
import opiam.admin.faare.struts.service.beans.JBOperator;
import opiam.admin.faare.unittests.TestResult;
import opiam.admin.faare.unittests.TestUtils;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;


/**
 * Test of the JBOperator class.
 */
public class JBOperatorTest extends TestCase
{
    /** Instance of logger. */
    private static Logger _logger = Logger.getLogger(JBOperatorTest.class);

    /** Instance of the trace class. */
    private static TestUtils _test = new TestUtils(_logger);

    /** Instance of JBOperator. */
    private JBOperator jbOperator = new JBOperator();

    /**
     * Creates a new JBOperatorTest object.
     *
     * @param arg0 Parameter.
     */
    public JBOperatorTest(String arg0)
    {
        super(arg0);

        try
        {
            PropertiesManager.getInstance();
        }
        catch (Exception e)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("TestTemplate constructor error\n");
            msg.append(e.toString());
            _test.displayResultFailure(msg.toString());
        }
    }

    /**
     * Method of the tests suite.
     *
     * @return Tests result.
     */
    public static Test suite()
    {
        TestSuite suite = new TestSuite();

        suite.addTest(new JBOperatorTest("testBegin"));

        suite.addTest(new JBOperatorTest("testGetName"));
        suite.addTest(new JBOperatorTest("testAddOpList"));

        suite.addTest(new JBOperatorTest("testEnd"));

        return suite;
    }

    /**
     * Main method of the test class.
     *
     * @param args  Sets of the parameters.
     */
    public static void main(String[] args)
    {
        junit.textui.TestRunner.run(suite());
    }

    /**
     * Method to indicate the beginning of the class test.
     *
     */
    public static void testBegin()
    {
        //  To initialize the tests statement
        TestResult.getInstance().setInitiator("JBOperatorTest");

        _test.displayHeaderClass("JBOperatorTest");
        assertTrue(true);
    }

    /**
     * Method to indicate the end of the class test.
     *
     */
    public static void testEnd()
    {
        _test.displayFooterClass(null);
        assertTrue(true);

        // To display the tests statement
        _test.displayTestStatement("JBOperatorTest");
    }

    /**
     * Test the methods: setName and getName.
     *
     */
    public void testGetName()
    {
        _test.displayHeaderMethod("testGetName");

        try
        {
            String expected = "search_sn";
            jbOperator.setName("search_sn");

            String result = jbOperator.getName();

            if (expected == result)
            {
                _test.displayResultSuccess(null);
            }
            else
            {
                _test.displayResultFailure(null);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testGetName");
    }

    /**
     * Test the methods: addOpList and getOperators.
     *
     */
    public void testAddOpList()
    {
        _test.displayHeaderMethod("testAddOpList");

        try
        {
            List opList1 = new ArrayList();
            List opList2 = new ArrayList();

            JBOperator ajbOperator = new JBOperator();

            opList1.add("BEGINS_WITH");

            ajbOperator.addOpList("BEGINS_WITH");
            opList2 = ajbOperator.getOperators();

            if (opList1.size() == opList2.size())
            {
                _test.displayResultSuccess(null);
            }
            else
            {
                _test.displayResultFailure(null);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testAddOpList");
    }
}
